﻿/**
 *  This handles the displaying of the splash screen when the program starts.
 *  If the Kinect is connected, it will show the splash screen until it has fully initialised.
 *  If the Kinect is not connected, an error will show that the program cannot start until it is connected.
 * */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace EHU_InterfaceProgramming
{
    /// <summary>
    /// Interaction logic for SplashScreen.xaml
    /// </summary>
    public partial class SplashScreen : Window
    {
        MainWindow mainwindow;

        public SplashScreen(MainWindow mainWindow)
        {
            InitializeComponent();
            mainwindow = mainWindow;
            show();
            updateKinectStatusImage();
        }

        /**
         * Show the splash screen along with all of the relevant logos and components
         **/
        public void show()
        {
            splashWindow1.Visibility = Visibility.Visible;
        }

        /**
         * Hide all components of the splash screen.
         * */
        public void hide()
        {
            splashWindow1.Visibility = Visibility.Hidden;
        }

        /**
         * Updates the current status message at the bottom of the splash screen
         * */
        public void setLoadingStatusMsg(String msg)
        {
            loadingText.Text = msg;
        }

        /**
         * Shows the appropriate image to determine if the Kinect
         * camera is connected or not
         * */
        public void updateKinectStatusImage()
        {
            if (mainwindow.isKinectConnected() == true)
            {
                kinectNotFound.Visibility = Visibility.Hidden;
                kinectFound.Visibility = Visibility.Visible;
            }
            else
            {
                kinectNotFound.Visibility = Visibility.Visible;
                kinectFound.Visibility = Visibility.Hidden;
                setLoadingStatusMsg("The Kinect camera cannot be found. Please connect it and relaunch the program.");
            }
        }

        /**
         * If the splash screen is closed then the program needs to terminate.
         * */
        private void splashScreen_CloseWindow(object sender, System.ComponentModel.CancelEventArgs e)
        {
            System.Environment.Exit(0);
        }

        private void refreshBtn_Click(object sender, RoutedEventArgs e)
        {
            updateKinectStatusImage();
            mainwindow.EnableKinect();
        }

    }
}
